package com.logicalthinking.socialmall.biz;

import com.github.chenlijia1111.utils.common.Result;
import com.github.chenlijia1111.utils.core.NumberUtil;
import com.logicalthinking.socialmall.common.pojo.Constants;
import com.logicalthinking.socialmall.entity.SystemConfig;
import com.logicalthinking.socialmall.service.SystemConfigServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 系统设置表
 *
 * @author chenLiJia
 * @since 2020-02-17 14:43:59
 **/
@Service
public class SystemConfigBiz {

    @Autowired
    private SystemConfigServiceI systemConfigService;//系统配置

    /**
     * 配置服务费比例 保留四位小数
     *
     * @param serviceFeeRatio
     * @return
     */
    public Result configServiceFee(Double serviceFeeRatio) {
        //保留四位小数
        serviceFeeRatio = NumberUtil.doubleToFixLengthDouble(serviceFeeRatio, 4);
        //修改
        SystemConfig systemConfig = systemConfigService.findByKey(Constants.SERVICE_FEE_RATIO_SYSTEM_CONFIG_KEY);
        systemConfig.setConfigValue(String.valueOf(serviceFeeRatio));
        return systemConfigService.update(systemConfig);
    }

    /**
     * 查询服务费比例
     * @return
     */
    public Result findServiceFee() {
        SystemConfig systemConfig = systemConfigService.findByKey(Constants.SERVICE_FEE_RATIO_SYSTEM_CONFIG_KEY);
        return Result.success("查询成功", systemConfig);
    }


}
